package middleware

import (
	"github.com/goravel/framework/contracts/http"
	"github.com/goravel/framework/facades"
)

func ConfigurationMiddleware() http.Middleware {
	return func(ctx http.Context) {
		//	获取header中的Configuration_id
		configuration_id := ctx.Request().Header("Configuration_id", "")
		facades.Log().Info("header-configuration_id", configuration_id)
		if configuration_id == "" {
			ctx.Request().AbortWithStatusJson(444, http.Json{
				"message": "请绑定配置后重试",
			})
			return
		} else {
			//把configuration_id放入上下文，在下文的ctx中获取
			ctx.WithValue("configuration_id", configuration_id)
			ctx.Request().Next()
		}
	}
}
